﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.BarterSystem.Barterables.GoldBarterable
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using System.Collections.Generic;
using TaleWorlds.CampaignSystem.Actions;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.Core;
using TaleWorlds.Localization;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem.BarterSystem.Barterables
{
  public class GoldBarterable : Barterable
  {
    [SaveableField(200)]
    private readonly int _maxGold;
    [SaveableField(201)]
    private readonly Hero _ownerHero;
    [SaveableField(202)]
    private readonly Hero _otherHero;
    [SaveableField(203)]
    private readonly PartyBase _otherParty;

    public override string StringID => "gold_barterable";

    public override int MaxAmount => this._maxGold;

    public override TextObject Name => GameTexts.FindText("str_char_denar_tooltip");

    public GoldBarterable(
      Hero owner,
      Hero other,
      PartyBase ownerParty,
      PartyBase otherParty,
      int val)
      : base(owner, ownerParty)
    {
      this._ownerHero = owner;
      this._otherHero = other;
      this._otherParty = otherParty;
      this._maxGold = val;
      this.CurrentAmount = 0;
    }

    public override int GetUnitValueForFaction(IFaction faction)
    {
      if (faction == this.OriginalOwner?.Clan || faction == this.OriginalOwner?.MapFaction || faction == this.OriginalParty?.MapFaction)
        return -1;
      return faction == this._otherHero?.Clan || faction == this._otherHero?.MapFaction || faction == this._otherParty?.MapFaction ? 1 : 0;
    }

    public override ImageIdentifier GetVisualIdentifier() => (ImageIdentifier) null;

    public override string GetEncyclopediaLink() => "";

    public override void Apply()
    {
      if (this._ownerHero != null && this._otherHero != null)
        GiveGoldAction.ApplyBetweenCharacters(this._ownerHero, this._otherHero, this.CurrentAmount);
      else if (this.OriginalParty != PartyBase.MainParty)
      {
        if (this._otherParty != PartyBase.MainParty)
          GiveGoldAction.ApplyForPartyToParty(this.OriginalParty, this._otherParty, this.CurrentAmount);
        else
          GiveGoldAction.ApplyForPartyToCharacter(this.OriginalParty, Hero.MainHero, this.CurrentAmount);
      }
      else
        GiveGoldAction.ApplyForCharacterToParty(Hero.MainHero, this._otherParty, this.CurrentAmount);
    }

    internal static void AutoGeneratedStaticCollectObjectsGoldBarterable(
      object o,
      List<object> collectedObjects)
    {
      ((Barterable) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      base.AutoGeneratedInstanceCollectObjects(collectedObjects);
      collectedObjects.Add((object) this._ownerHero);
      collectedObjects.Add((object) this._otherHero);
      collectedObjects.Add((object) this._otherParty);
    }

    internal static object AutoGeneratedGetMemberValue_maxGold(object o)
    {
      return (object) ((GoldBarterable) o)._maxGold;
    }

    internal static object AutoGeneratedGetMemberValue_ownerHero(object o)
    {
      return (object) ((GoldBarterable) o)._ownerHero;
    }

    internal static object AutoGeneratedGetMemberValue_otherHero(object o)
    {
      return (object) ((GoldBarterable) o)._otherHero;
    }

    internal static object AutoGeneratedGetMemberValue_otherParty(object o)
    {
      return (object) ((GoldBarterable) o)._otherParty;
    }
  }
}
